package controller

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"testGin/entity"
	"testGin/tool"
)

func Type(c *gin.Context) {
	// 查询
	var types []entity.Type
	GetDB().Find(&types)
	c.JSON(http.StatusOK, tool.R{
		200, "获取成功", types,
	})
}

func ChangeType(c *gin.Context) {
	loginUser := entity.GetUser(c)
	if loginUser.Id <= 0 {
		c.JSON(http.StatusForbidden, tool.R{
			403, "请求参数错误", nil,
		})
		return
	}
	GetDB().Model(&entity.User{}).Where("id = ?", loginUser.Id).Update("type", loginUser.Type)
	c.JSON(http.StatusOK, tool.R{
		200, "修改喜好成功", nil,
	})
}
